package cn.sdhuijin.healthexam.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import cn.sdhuijin.healthexam.ExitApplication;
import cn.sdhuijin.healthexam.R;
import cn.sdhuijin.healthexam.control.AbstractControlActivity;
import cn.sdhuijin.healthexam.util.Constants;

/**
 * 新建人员档案
 * 
 * @author houyuchun
 * 
 */
public class EditPersonDocSecondActivity extends AbstractControlActivity
		implements OnClickListener, OnCheckedChangeListener {

	// 创建日期
	private String createDate;
	// 药物过敏
	private int[] checkYwgmIds = { R.id.check_medical_guomin_a,
			R.id.check_medical_guomin_b, R.id.check_medical_guomin_c };
	// 暴漏史选项
	private int[] checkBlsIds = { R.id.check_baoloushi_a,
			R.id.check_baoloushi_b, R.id.check_baoloushi_c };
	// 疾病史
	private int[] checkJbsIds = { R.id.check_jibing_gaoxueya,
			R.id.check_jibing_tangniaobing, R.id.check_jibing_guanxinbing,
			R.id.check_jibing_manxzsxingjb, R.id.check_jibing_exingzhongliu,
			R.id.check_jibing_naozuzhong, R.id.check_jibing_jingshenbing,
			R.id.check_jibing_jiehebing, R.id.check_jibing_ganyan,
			R.id.check_jibing_chuanranbing, R.id.check_jibing_zhiyebing };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 去掉标题
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_edit_doc_second);
		ExitApplication.getInstance().addActivity(this);

		Intent intent = getIntent();
		// 创建日期ID
		Bundle bundle = intent.getBundleExtra("bundle");
		if (bundle != null) {
			createDate = bundle.getString("createDate");
		}
		setCurrentEditUserName(createDate);
		addRadioGroupView(R.id.rad_wenhuachengdu, "文化程度");
		addRadioGroupView(R.id.rad_zhiye, "职业");
		addRadioGroupView(R.id.rad_medical_pay, "医药支付");
		addCheckBoxView(checkYwgmIds, "药物过敏");
		addCheckBoxView(checkBlsIds, "暴露史");
		addCheckBoxView(checkJbsIds, "疾病史");
		addEditTextView(R.id.edt_guominshi_qita, "其他药物过敏史");
		addEditTextView(R.id.edt_jibing_qita, "其他疾病史");
		addEditTextView(R.id.edt_jibing_gaoxueya_date, "高血压确诊时间");
		addEditTextView(R.id.edt_jibing_tangniaobing_date, "糖尿病确诊时间");
		addEditTextView(R.id.edt_jibing_guanxinbing_date, "冠心病确诊时间");
		addEditTextView(R.id.edt_jibing_manxzsxingjb_date, "慢性阻塞性肺疾病确诊时间");
		addEditTextView(R.id.edt_jibing_exingzhongliu_date, "恶性肿瘤确诊时间");
		addEditTextView(R.id.edt_jibing_naozuzhong_date, "脑卒中确诊时间");
		addEditTextView(R.id.edt_jibing_jingshenbing_date, "重性精神疾病确诊时间");
		addEditTextView(R.id.edt_jibing_jiehebing_date, "结核病确诊时间");
		addEditTextView(R.id.edt_jibing_ganyan_date, "肝炎确诊时间");
		addEditTextView(R.id.edt_jibing_chuanranbing_date, "其他法定传染病确诊时间");
		addEditTextView(R.id.edt_jibing_zhiyebing_date, "职业病确诊时间");

		CheckBox cb1 = (CheckBox) findViewById(R.id.check_jibing_gaoxueya);
		cb1.setOnCheckedChangeListener(this);
		CheckBox cb2 = (CheckBox) findViewById(R.id.check_jibing_tangniaobing);
		cb2.setOnCheckedChangeListener(this);
		CheckBox cb3 = (CheckBox) findViewById(R.id.check_jibing_guanxinbing);
		cb3.setOnCheckedChangeListener(this);
		CheckBox cb4 = (CheckBox) findViewById(R.id.check_jibing_manxzsxingjb);
		cb4.setOnCheckedChangeListener(this);
		CheckBox cb5 = (CheckBox) findViewById(R.id.check_jibing_exingzhongliu);
		cb5.setOnCheckedChangeListener(this);
		CheckBox cb6 = (CheckBox) findViewById(R.id.check_jibing_naozuzhong);
		cb6.setOnCheckedChangeListener(this);
		CheckBox cb7 = (CheckBox) findViewById(R.id.check_jibing_jingshenbing);
		cb7.setOnCheckedChangeListener(this);
		CheckBox cb8 = (CheckBox) findViewById(R.id.check_jibing_jiehebing);
		cb8.setOnCheckedChangeListener(this);
		CheckBox cb9 = (CheckBox) findViewById(R.id.check_jibing_ganyan);
		cb9.setOnCheckedChangeListener(this);
		CheckBox cb10 = (CheckBox) findViewById(R.id.check_jibing_chuanranbing);
		cb10.setOnCheckedChangeListener(this);
		CheckBox cb11 = (CheckBox) findViewById(R.id.check_jibing_zhiyebing);
		cb11.setOnCheckedChangeListener(this);

		// Properties文件路径
		controlManager.setPropertiesPath(Constants.PROPERTIES_PATH + createDate
				+ ".txt");
		Log.i(EditPersonDocSecondActivity.class.getSimpleName(), "文件路径： "
				+ Constants.PROPERTIES_PATH + createDate + ".txt");
		controlManager.toControl();

		setEditTextListener(R.id.edt_jibing_gaoxueya_date);
		setEditTextListener(R.id.edt_jibing_tangniaobing_date);
		setEditTextListener(R.id.edt_jibing_guanxinbing_date);
		setEditTextListener(R.id.edt_jibing_manxzsxingjb_date);
		setEditTextListener(R.id.edt_jibing_exingzhongliu_date);
		setEditTextListener(R.id.edt_jibing_naozuzhong_date);
		setEditTextListener(R.id.edt_jibing_jingshenbing_date);
		setEditTextListener(R.id.edt_jibing_jiehebing_date);
		setEditTextListener(R.id.edt_jibing_ganyan_date);
		setEditTextListener(R.id.edt_jibing_chuanranbing_date);
		setEditTextListener(R.id.edt_jibing_zhiyebing_date);

		this.setButtonListener(this, R.id.btn_next, R.id.btn_previous);
	}

	/**
	 * 按钮点击处理事件
	 */
	@Override
	public void onClick(View arg0) {
		Intent intent = new Intent();
		Bundle bundle = new Bundle();
		// 获取点击按钮
		int id = (Integer) arg0.getId();
		switch (id) {
		case R.id.btn_previous:
			controlManager.toProperties();
			bundle.putString("createDate", createDate);
			// 创建日期
			intent.putExtra("bundle", bundle);
			// 前一页按钮
			intent.setClass(this, EditPersonDocFirstActivity.class);
			startActivity(intent);
			this.finish();
			break;
		case R.id.btn_next:
			// 保存当前信息到Bean
			controlManager.toProperties();
			bundle.putString("createDate", createDate);
			// 创建日期
			intent.putExtra("bundle", bundle);
			// 前一页按钮
			intent.setClass(this, EditPersonDocThirdActivity.class);
			startActivity(intent);
			this.finish();
			break;
		default:
			break;
		}
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if (buttonView.getId() == R.id.check_jibing_gaoxueya) {
			if (isChecked) {
				((EditText) findViewById(R.id.edt_jibing_gaoxueya_date))
						.setEnabled(true);
			} else {
				((EditText) findViewById(R.id.edt_jibing_gaoxueya_date))
						.setEnabled(false);
				((EditText) findViewById(R.id.edt_jibing_gaoxueya_date))
						.setText("");
				;
			}
		}
		if (buttonView.getId() == R.id.check_jibing_tangniaobing) {
			if (isChecked) {
				((EditText) findViewById(R.id.edt_jibing_tangniaobing_date))
						.setEnabled(true);
			} else {
				((EditText) findViewById(R.id.edt_jibing_tangniaobing_date))
						.setEnabled(false);
				((EditText) findViewById(R.id.edt_jibing_tangniaobing_date))
						.setText("");
				;
			}
		}
		if (buttonView.getId() == R.id.check_jibing_guanxinbing) {
			if (isChecked) {
				((EditText) findViewById(R.id.edt_jibing_guanxinbing_date))
						.setEnabled(true);
			} else {
				((EditText) findViewById(R.id.edt_jibing_guanxinbing_date))
						.setEnabled(false);
				((EditText) findViewById(R.id.edt_jibing_guanxinbing_date))
						.setText("");
				;
			}
		}
		if (buttonView.getId() == R.id.check_jibing_manxzsxingjb) {
			if (isChecked) {
				((EditText) findViewById(R.id.edt_jibing_manxzsxingjb_date))
						.setEnabled(true);
			} else {
				((EditText) findViewById(R.id.edt_jibing_manxzsxingjb_date))
						.setEnabled(false);
				((EditText) findViewById(R.id.edt_jibing_manxzsxingjb_date))
						.setText("");
				;
			}
		}
		if (buttonView.getId() == R.id.check_jibing_exingzhongliu) {
			if (isChecked) {
				((EditText) findViewById(R.id.edt_jibing_exingzhongliu_date))
						.setEnabled(true);
			} else {
				((EditText) findViewById(R.id.edt_jibing_exingzhongliu_date))
						.setEnabled(false);
				((EditText) findViewById(R.id.edt_jibing_exingzhongliu_date))
						.setText("");
				;
			}
		}
		if (buttonView.getId() == R.id.check_jibing_naozuzhong) {
			if (isChecked) {
				((EditText) findViewById(R.id.edt_jibing_naozuzhong_date))
						.setEnabled(true);
			} else {
				((EditText) findViewById(R.id.edt_jibing_naozuzhong_date))
						.setEnabled(false);
				((EditText) findViewById(R.id.edt_jibing_naozuzhong_date))
						.setText("");
				;
			}
		}
		if (buttonView.getId() == R.id.check_jibing_jingshenbing) {
			if (isChecked) {
				((EditText) findViewById(R.id.edt_jibing_jingshenbing_date))
						.setEnabled(true);
			} else {
				((EditText) findViewById(R.id.edt_jibing_jingshenbing_date))
						.setEnabled(false);
				((EditText) findViewById(R.id.edt_jibing_jingshenbing_date))
						.setText("");
				;
			}
		}
		if (buttonView.getId() == R.id.check_jibing_jiehebing) {
			if (isChecked) {
				((EditText) findViewById(R.id.edt_jibing_jiehebing_date))
						.setEnabled(true);
			} else {
				((EditText) findViewById(R.id.edt_jibing_jiehebing_date))
						.setEnabled(false);
				((EditText) findViewById(R.id.edt_jibing_jiehebing_date))
						.setText("");
				;
			}
		}
		if (buttonView.getId() == R.id.check_jibing_ganyan) {
			if (isChecked) {
				((EditText) findViewById(R.id.edt_jibing_ganyan_date))
						.setEnabled(true);
			} else {
				((EditText) findViewById(R.id.edt_jibing_ganyan_date))
						.setEnabled(false);
				((EditText) findViewById(R.id.edt_jibing_ganyan_date))
						.setText("");
				;
			}
		}
		if (buttonView.getId() == R.id.check_jibing_chuanranbing) {
			if (isChecked) {
				((EditText) findViewById(R.id.edt_jibing_chuanranbing_date))
						.setEnabled(true);
			} else {
				((EditText) findViewById(R.id.edt_jibing_chuanranbing_date))
						.setEnabled(false);
				((EditText) findViewById(R.id.edt_jibing_chuanranbing_date))
						.setText("");
				;
			}
		}
		if (buttonView.getId() == R.id.check_jibing_zhiyebing) {
			if (isChecked) {
				((EditText) findViewById(R.id.edt_jibing_zhiyebing_date))
						.setEnabled(true);
			} else {
				((EditText) findViewById(R.id.edt_jibing_zhiyebing_date))
						.setEnabled(false);
				((EditText) findViewById(R.id.edt_jibing_zhiyebing_date))
						.setText("");
				;
			}
		}

	}

}
